/*
 * @Author: ChunLai
 * @Date: 2022-02-18 10:13:09
 * @LastEditTime: 2025-11-18 17:24:23
 * @Description: 首页配置数据
 * @FilePath: \01.latest-short-insure\src\store\modules\home.js
 */
const state = {
  mustReadPop: "0", // 首页必读弹窗，是否打开
  recordName: "", // 备案名
  bannerImg: "",
  productImg: [], // 产品详情图(后台上传)
  questions: [], // 问答(后台上传)
  lipeiText: null, //(后台上传) 理赔: 字符串类型(保司提供的图片); 数据类型(列表文本展示)
  shareInfo: null, // 分享配置信息
  insuPlan: [], // 保险计划
  planModule: [], //保障计划
  apiClauseList: [], // 险种条款(产品特有的,后台上传的pdf)
  /* === 签名 === */
  fileType: "99", // 赋值签名图片地址的文件标识
  /* === 签名板 === */
  userType: "", // 用户类型
  signName: "", // 签名板显示用户名
  openSign: false,
  /* === 签名板-END === */
  userObj: {},
  signDoneFlag: false,
};

const getters = {
  mustReadPop: (state) => state.mustReadPop,
  recordName: (state) => state.recordName,
  planModule: (state) => state.planModule,
  bannerImg: (state) => state.bannerImg,
  lipeiText: (state) => state.lipeiText,
  productImg: (state) => state.productImg,
  insuPlan: (state) => state.insuPlan,
  questions: (state) => state.questions,
  shareInfo: (state) => state.shareInfo,
  baseConfig: (state) => state.baseConfig,
  apiClauseList: (state) => state.apiClauseList,
  /* === 签名 === */
  userType: (state) => state.userType,
  signName: (state) => state.signName,
  openSign: (state) => state.openSign,
  userObj: (state) => state.userObj,
  fileType: (state) => state.fileType,
  signDoneFlag: (state) => state.signDoneFlag,
};

const mutations = {
  updateField(state, payload) {
    Object.assign(state, payload);
  },
  SET_READ_POP(state, payload) {
    state.mustReadPop = payload;
  },
  setHomeField(state, payload) {
    for (const key in state) {
      if (Object.prototype.hasOwnProperty.call(payload, key)) {
        const item = payload[key];
        state[key] = item;
      }
    }
  },
  SET_SIGN_OBJ(state, payload) {
    state.userObj = {};
    state.userObj = payload;
  },
  CHANGE_SIGN_BOARD(state, payload) {
    state.openSign = payload;
  },
  CHANGE_SIGN_FLAG(state, payload) {
    state.signDoneFlag = payload;
  },
};
const actions = {
  /*后台险种配置需要展示的产品条款 投保文档等*/
  setClauseFiles({ state }, data) {
    // console.log('setClauseFiles',data)
    let arr = [];
    const len = data.length;
    for (let i = 0; i < len; i++) {
      const item = data[i];
      if (item.fileList && item.fileList.length > 0) {
        arr = [...arr, ...item.fileList];
      }
    }
    state.apiClauseList = arr;
  },
};

export default {
  namespaced: true,
  state,
  getters,
  mutations,
  actions,
};
